package com.darkplanet.management.dao;

import com.darkplanet.management.domain.SecondMenu;
import com.darkplanet.management.util.JDBCUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class SecondMenuDaoimpl implements ISecondMenuDao {
    QueryRunner queryRunner=new QueryRunner(JDBCUtil.getDs());
    @Override
    public SecondMenu getSecondMenuById(Integer id) {
       SecondMenu secondMenu=null;
        String sql="select * from secondmenu where s_menu_id=?";
        try {
            secondMenu=queryRunner.query(sql,new BeanHandler<>(SecondMenu.class),id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return secondMenu;
    }

    @Override
    public List<SecondMenu> getSecondMenus() {
        List <SecondMenu> roles=null;
        String sql="select * from secondmenu";
        try {
            roles=queryRunner.query(sql,new BeanListHandler<SecondMenu>(SecondMenu.class));
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return roles;
    }

    @Override
    public void addSecondMenu(Integer f_menu_id, String s_menu_name, String s_menu_path, String remark) {
        String sql="insert into secondmenu (f_menu_id,s_menu_name,s_menu_path,remark)";
        try {
            queryRunner.update(sql,f_menu_id,s_menu_name,s_menu_path,remark);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }


    @Override
    public void deleteSecondMenuById(Integer s_menu_id) {
              String sql="delete from secondmenu where s_menu_id=?";
        try {
            queryRunner.update(sql,s_menu_id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void updateSecondMenu(Integer f_menu_id, String s_menu_name, String s_menu_path, String remark) {
        String sql="update secondmenu set f_menu_id=?,s_menu_name=?,s_menu_path=?,remark=? ";
        try {
            queryRunner.update(sql,f_menu_id,s_menu_name,s_menu_path,remark);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }


}
